package com.yinhe.music.yhmusic.dialog;

import android.content.Context;
import android.support.v7.app.AlertDialog;

import java.lang.ref.WeakReference;

public class DownloadDialog {

    private WeakReference<Context> mContext;

    private int size;

    private AlertDialog.Builder mDialog;

    private DownloadDialogListener mListener;

    public interface DownloadDialogListener {
        void downDidConfirm();
    }

    public DownloadDialog(Context context, int size, DownloadDialogListener listener) {
        mContext = new WeakReference<>(context);
        this.size = size;
        mListener = listener;
        init();
    }

    public void show() {
        if (mDialog != null) {
            mDialog.show();
        }
    }

    private void init() {
        mDialog = new AlertDialog.Builder(mContext.get());
        mDialog.setMessage("将下载" + size + "首歌曲,大约会占用" + size * 5 + "M空间");
        mDialog.setPositiveButton("下载", (dialogInterface, i) -> {
            mListener.downDidConfirm();
        });
        mDialog.setNegativeButton("取消", null);
    }

}
